<template>
	<view class="device">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				设备安装
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}"></view>
		<view class="saoma">
			<image :src="baseUrl + '/wximage/saoma.png'" class="bj"></image>
			<view class="name">扫码绑定设备</view>
		</view>
		<view class="footer" @click="scanCode">
			<view class="iconfont icon-iconfontscan"></view>
			<view class="submit">开始绑定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
		},
		methods: {
			scanCode(){
				
				console.log("进入到设备绑定开始");
				// console.log(uni.getStorageSync('puhuobussiness_id'));
				// console.log(uni.getStorageSync('puhuobuzhou'));
				// var puhuobuzhou = ;
				// return false;
				//判断一下子是否有正在进行中的铺货
				//查看是否有进行到半路的
				if(!(uni.getStorageSync('puhuobussiness_id') == undefined||uni.getStorageSync('puhuobussiness_id') == null||uni.getStorageSync('puhuobussiness_id') == '')){
					console.log("走到真理了");
					uni.showModal({
					    title: '提示',
					    content: '当前存在未完成的新商户入驻流程，是否继续',
					    success: function (res) {
					        if (res.confirm) {
					            // console.log('用户点击确定');
								var puhuobuzhou = uni.getStorageSync('puhuobuzhou');
								
								if(puhuobuzhou == ''||puhuobuzhou == undefined||puhuobuzhou == null){
									
									uni.removeStorageSync('puhuobuzhou');
									
									uni.removeStorageSync('device_stores_id');
									
									uni.removeStorageSync('puhuobussiness_id');
									
									uni.removeStorageSync('deviceidm');
									
									uni.removeStorageSync('deviceidk');
									
								}
								
								//查看一下入驻到第几步了
								if(puhuobuzhou == '2'){
									//跳转到新建门店中
									uni.redirectTo({
										url: '/subpackageA/device/store'
									})
								}else if(puhuobuzhou == '3'){
									//跳转到开通分成中
									uni.redirectTo({
										url: '/subpackageA/device/divide'
									})
								}else if(bussiness_ruzhu=='4'){
									//跳转到开通分成中
									uni.redirectTo({
										url: '/subpackageA/device/success'
									})
								}
					            // 用户点击了确定按钮的相关逻辑可以放在这里
					        } else if (res.cancel) {
								uni.removeStorageSync('puhuobuzhou');
								
								uni.removeStorageSync('device_stores_id');
								
								uni.removeStorageSync('puhuobussiness_id');
								
								uni.removeStorageSync('deviceidm');
								
								uni.removeStorageSync('deviceidk');
								
								
								uni.redirectTo({
									url: '/subpackageA/device/detail'
								})
					            // 用户点击了取消按钮的相关逻辑可以放在这里
					        }
					    }
					});
				}else{
					uni.redirectTo({
						url: '/subpackageA/device/detail'
					})
				}
				
				
				
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.device {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
		}

		.saoma {
			width: 94%;
			margin: 0 auto;
			margin-top: -190rpx;
			text-align: center;

			.bj {
				width: 400rpx;
				height: 406rpx;
			}

			.name {
				font-size: 36rpx;
				color: #333333;
				font-weight: 700;
				margin-top: 6rpx;
			}
		}

		.footer {
			width: 80%;
			margin: 0 auto 40rpx;
			margin-top: 360rpx;
			height: 72rpx;
			text-align: center;
			background: linear-gradient(90deg, #65bdfc, #398ef8);
			border-radius: 36rpx;
			border-top-left-radius: 0;
			border-bottom-left-radius: 42rpx;

			.iconfont {
				display: inline-block;
				margin-right: 14rpx;
				font-size: 34rpx;
				color: #ffffff;
			}

			.submit {
				display: inline-block;
				height: 72rpx;
				line-height: 72rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}
</style>